layui.use(['form', 'jquery', 'jquery_cookie'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);


    // 进行注册操作
    form.on('submit(registerUser)', function (data) {
        data = data.field;
        if (data.userName == "undefined" || data.username == "" || data.username.trim() == "") {
            layer.msg('注册账号不能为空');
            return false;
        }
        if (data.trueName == "undefined" || data.trueName == "" || data.trueName.trim() == "") {
            layer.msg('真实姓名不能为空');
            return false;
        }
        if (data.password == "undefined" || data.password == "" || data.password.trim() == "") {
            layer.msg('密码不能为空');
            return false;
        }
        $.ajax({
            type: "post",
            url: ctx + "/user/registerUser",
            data: {
                userName: data.username,
                password: data.password,
                trueName: data.trueName
            },
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    layer.alert('注册成功', function () {
                        window.location.href = ctx + "/index";
                    });
                } else {
                    layer.alert(data.message);
                }
            }
        });
        return false;
    });
});